package com.itheima.a_cookie;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class GetCookieServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//获取浏览器的cookie
		Cookie[] cookies = request.getCookies();
		//判断cookies是否为null
		if(cookies!=null){
			for(Cookie cookie:cookies){
				//查找akey的cookie
				if("akey".equals(cookie.getName())){
					System.out.println(cookie.getValue());
				}
			}
		}
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
}